package com.qifenqian.turbot.module.model

import android.content.Context

import com.qifenqian.turbot.base.BaseModel
import com.qifenqian.turbot.module.contract.StaffContract
import com.qifenqian.turbot.module.entity.response.StaffEntity
import com.qifenqian.turbot.net.ModelCallback
import com.qifenqian.turbot.net.NetObserver

/**
 * @author H
 * @createTime 2018/12/27 11:19
 * @description
 * @see
 * @since
 */
class StaffModel(context: Context) : BaseModel(context), StaffContract.Model {

    override fun deleteStaff(id: Int, callback: ModelCallback<Nothing>) {
        mClient!!.deleteStaff(id)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun editStaff(id: Int, userName: String, userCode: String, callback: ModelCallback<Nothing>) {
        mClient!!.editStaff(id, userName, userCode)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun addStaff(userName: String, userCode: String, callback: ModelCallback<Double>) {
        mClient!!.addStaff(userName, userCode)
                .subscribe(object : NetObserver<Double>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Double?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getStaffList(callback: ModelCallback<List<StaffEntity>>) {
        mClient!!.getStaffList()
                .subscribe(object : NetObserver<List<StaffEntity>>(mContext, true) {
                    override fun onSuccess(msg: String?, t: List<StaffEntity>?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }
}
